package com.five.dao.impl.backstage;

import com.five.dao.backstage.PanDianDao;
import com.five.util.DBUtil;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: jianglin
 * Date: 2020/12/2  9:06
 */
@Repository
public class PanDianDaoImpl implements PanDianDao {

    @Override
    public List<Map> pdQuery() {
        String sql="select id ssid,name,count as count from t_facility";
        return DBUtil.queryMap(sql);
    }

    @Override
    public int addPianDian(Map map) {
        String sql="insert into t_pandian(pddate,pdrid,pdrid2) values(now(),?,?)";
        return DBUtil.getKey(sql,map.get("pdra"),map.get("pdrb"));
    }

    @Override
    public List<Map> pdrId(Integer page, Integer limit) {
        String sql="select p.id id,p. pddate, p.pdrid pdra,p.pdrid2 pdrb from t_pandian p limit ?,?";
        return DBUtil.queryMap(sql,(page-1)*limit,limit);
    }

    @Override
    public int count() {
        String sql=" select count(*) a from t_pandian";
        List<Map> maps = DBUtil.queryMap(sql);
        String a = maps.get(0).get("a") + "";
        int i = Integer.parseInt(a);
        return i;
    }
    @Override
    public int addPdXq(Map map1, int a) {
        String sql="insert into t_pandianxq(pdid,ssid,sjcount,count,comm)values(?,?,?,?,?)";
        return DBUtil.manage(sql,a,map1.get("ssid"),map1.get("faccount"),map1.get("count"),map1.get("comm"));
    }

    @Override
    public int addPdXqs(Map map1) {
        String sql="update t_facility set count=? where id=?";
        return DBUtil.manage(sql,map1.get("faccount"),map1.get("ssid"));
    }

    @Override
    public List<Map> pdQueryId(Integer id) {
        String sql= "SELECT tp.*,ts.name  from t_pandianxq tp,t_facility ts WHERE tp.ssid=ts.id AND tp.pdid=?";
        return DBUtil.queryMap(sql,id);
    }



}
